const serialize = (obj) => {
    let str = [];

    for (let p in obj) {
        // eslint-disable-next-line no-prototype-builtins
        if (obj.hasOwnProperty(p)) {
            str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
        }
    }

    return str.length > 0 ? '?' + str.join('&') : '';
};
const formatUrl = (url, method, params) => {
    return url + ((method === 'GET' && serialize(params)) || '');
};
const formatConfig = (method, params, config = {}) => {
    config.method = method;
    if (method === 'POST') {
        config.body = JSON.stringify(params);
        config.headers = { 'Content-Type': 'application/json' };
        return config;
    }
};
export default async function getDatabase(method, params) {
    const res = await fetch(
        formatUrl('/api/test/getApplicationV2', method, params),
        formatConfig(method, params, {})
    );
    return await res.json();
}
